numeros = {"zero": "0", "one": "1", "two": "2", "three": "3", "four": "4", "five": "5", "six": "6", "seven": "7", "eight": "8", "nine": "9"}
num = input().split()
try:
    num = int("".join(map(lambda x: numeros[x], num)))
except Exception:
    print("Wrong input")
    exit(1)

def is_prime(num: int):
    for i in range(2, num):
        if num % i == 0:
            return False

    return True

less_prime = num
bigger_prime = num

while not is_prime(less_prime):
    less_prime -= 1

while not is_prime(bigger_prime):
    bigger_prime += 1

if num - less_prime < bigger_prime - num:
    print(less_prime)
else:
    print(bigger_prime)
